package com.qf.qflivehou.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.qflivehou.mapper.QfCommentDao;
import com.qf.qflivehou.pojo.respVo.CommentUserResp;
import com.qf.qflivehou.pojo.respVo.ResponseData;
import com.qf.qflivehou.pojo.vo.QfComment;
import com.qf.qflivehou.service.QfCommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (QfComment)表服务实现类
 *
 * @author makejava
 * @since 2022-01-11 20:40:07
 */
@Service
public class QfCommentServiceImpl implements QfCommentService {
    @Resource
    private QfCommentDao qfCommentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public QfComment queryById(Integer id) {
        return this.qfCommentDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<QfComment> queryAllByLimit(int offset, int limit) {
        return this.qfCommentDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param qfComment 实例对象
     * @return 实例对象
     */
    @Override
    public QfComment insert(QfComment qfComment) {
        this.qfCommentDao.insert(qfComment);
        return qfComment;
    }

    /**
     * 修改数据
     *
     * @param qfComment 实例对象
     * @return 实例对象
     */
    @Override
    public QfComment update(QfComment qfComment) {
        this.qfCommentDao.update(qfComment);
        return this.queryById(qfComment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.qfCommentDao.deleteById(id) > 0;
    }

    @Override
    public ResponseData findCourseCommentByCourseId(Integer id, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<CommentUserResp> comments = qfCommentDao.findCourseCommentByCourseId(id);
        PageInfo<CommentUserResp> of = PageInfo.of(comments);
        System.out.println(of.getSize());
        if(of!=null && of.getSize()>0){
            return new ResponseData(0,"查询成功",of.getList(),of.getTotal());
        }
        return new ResponseData().fail();
    }
}